﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;

namespace Itop.YHPC.demo {
    public partial class wfUser : System.Web.UI.Page {
        protected void Page_Load(object sender, EventArgs e) {

            string action = Request.QueryString["action"];
            //读取上传的数据流
            System.IO.StreamReader sr = new System.IO.StreamReader(Request.InputStream, Encoding.UTF8);
            string json = sr.ReadToEnd();
            json = util.U2G(json);//字符串中的中文unicode字符转成中文

            string ret = "";//返回字符串
            if (action == "read") {//查询数据
                ret = read(json);
            } else if (action == "create") {//增加对象
                ret = create(json);
            } else if (action == "update") {//更新对象
                ret = update(json);
            } else if (action == "delete") {//删除对象
                ret = delete(json);
            }  
            Response.Output.Write(ret);
            Response.End();
        }
        private string read(string json) {
            //json里可能有分页信息
            //string str = "[{firstName : 'Lou中is', lastName  : 'Dobbs',dob       : '12/21/34',  userName  : 'ldobbs' }]";
            UserModel model = new UserModel() { firstName = "Lou中is", lastName = "Dobbs", dob = "12/21/34", userName = "ldobbs" };
            string ret = Newtonsoft.Json.JsonConvert.SerializeObject(model);
            return ret;
        }
        private string update(string json) {
            if (string.IsNullOrEmpty(json)) return "";
            UserModel model = Newtonsoft.Json.JsonConvert.DeserializeObject<UserModel>(json);
            if (model != null) {
                //update code;
            }
            return "OK";
        }
        private string create(string json) {
            if (string.IsNullOrEmpty(json)) return "";
            UserModel model = Newtonsoft.Json.JsonConvert.DeserializeObject<UserModel>(json);
            if (model != null) {
                //create code;
            }
            return "OK";
        }
        private string delete(string json) {
            if (string.IsNullOrEmpty(json)) return "";
            UserModel model = Newtonsoft.Json.JsonConvert.DeserializeObject<UserModel>(json);
            if (model != null) {
                //delete code;
            }
            return "OK";
        }
       

    }
}
